package com.wry.wry_test.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.FileInputStream;
import java.io.InputStream;

public class YamlTransformToJson {

    public static void main(String[] args) throws Exception {
        // 创建 ObjectMapper 实例，用于序列化和反序列化
        ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); // 用于读取YAML
        ObjectMapper jsonMapper = new ObjectMapper(); // 用于输出JSON

        // 从YAML字符串、文件或输入流读取数据
        InputStream is = new FileInputStream("E:\\工作文档\\data\\iserver-openapi-public-all.yaml");
        // 解析YAML
        Object obj = objectMapper.readValue(is, Object.class);

        // 将对象转换为JSON
        String jsonOutput = jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);

        // 输出JSON
        System.out.println(jsonOutput);
    }
}
